(function() {
    function Util() {
        //
    }

    /**
     * 获取请求参数列表
     * @returns {{}}
     */
    Util.prototype.getRequestParameters = function () {
        var arr = (location.search || "").replace(/^\?/, '').split("&");
        var params = {};
        for (var i = 0; i < arr.length; i++) {
            var data = arr[i].split("=");
            if (data.length == 2) {
                params[data[0]] = data[1];
            }
        }
        return params;
    }

    /**
     * 获取请求参数
     * @param key
     * @returns {*}
     */
    Util.prototype.getRequestParameter = function (_key) {
        var params = this.getRequestParameters();
        return params[_key];
    }

    /**
     * 获取hash参数列表
     * @return {*}
     * **/
     Util.prototype.getHashParameters = function () {
        var arr = (location.hash || "").replace(/^\#/, '').split("&");
        var params = {};
        for (var i = 0; i < arr.length; i++) {
            var data = arr[i].split("=");
            if (data.length == 2) {
                params[data[0]] = data[1];
            }
        }
        return params;
    }

    /**
     * 获取hash参数
     * @param key
     * @returns {*}
     */
    Util.prototype.getHashParameter = function (_key) {
        var params = this.getHashParameters();
        return params[_key];
    }

    /**
     * 获取cookies列表
     * @param _name
     * @return {*}
     * **/
    Util.prototype.getCookies = function (_name) {
        var arr, reg = new RegExp("(^| )" + _name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg)) {
            var result = unescape(arr[2]);
            result = result.replace(/^\"|\"$/g, "").replace(/\\\"/g, "\"");
            try {
                return JSON.parse(result);
            }
            catch (e) {
            }
            return result;
        }
        else {
            return null;
        }
    }

    //转换日期为unix时间戳
    Util.prototype.formateUnixDate = function(_date) {
        var date = new Date(_date);
        return Math.round(date.getTime());
    }
 
    //转换日期为UTC
    Util.prototype.formateUtcDate = function(_date) {
        return new Date(_date).toISOString();
    }

    window.Util = Util;
})(window);